export interface ITool {
    id: number;
    name: string;
    price: number; // 原价
    discountPrice: number; // 折扣价
    downloadTimes: number;
}

export interface IOrder {
    orderId: string; // 订单号
    codeUrl: string; // 二维码地址，用于支付
}

export interface IOrderStatus {
    taskId: string
    status: number; // // 0：支付成功 1：支付中 2：订单创建失败 3：取消支付 4：转入退款 5：未支付 6：已关闭 7：已撤销 8：已退款 999：支付失败（带其他具体原因）
    message: string; // 状态描述
}
export function getToolMsg(toolId: number) {
    return get<ITool | string>("tool", {
        headers: {
            "tool-id": toolId,
        }
    });
}

export function getDownTimesApi(taskId: string, toolId: number) {
    return get<number | string>("downTimes", requestConfig(taskId, toolId));
}

export function wechatOrder(taskId: string, toolId: number) {
    return get<IOrder | string>("order/wechatOrder", requestConfig(taskId, toolId));
}

export function wechatOrderFirst(toolId: number) {
    return get<IOrder | string>("order/wechatOrderFirst", {
        headers: {
            "tool-id": toolId,
        },
    });
}

export function getOrderStatusApi(orderId: string) {
    return get<IOrderStatus | string>("order/status/" + orderId);
}

export function requestConfig(taskId: string, toolId: number) {
    return {
        headers: {
            "task-id": taskId,
            "tool-id": toolId,
        },
    };
}
